Function not returning value at all - not a void [migrated]

Posted by user105439 on Programmers See other posts from Programmers or by user105439
Published on 2013-10-19T13:35:56Z Indexed on 2013/10/19 16:08 UTC
Read the original article Hit count: 123

Filed under:

I have this function that is not returning a function value. I've added some random testers to try and debug but no luck. Thanks!

#include <stdio.h>
#include <math.h>
#include <time.h>

#define N 100

float error(int a, int b); 

int main(){
    printf("START\n");

    srand(time(NULL)); 

    int a, b, j, m;
    float plot[N+1]; 

    printf("Lower bound for x: ");
    scanf("%d", &a);

    printf("Upper bound for x: ");
    scanf("%d", &b); 

    printf("okay\n");

    for(j = 0; j < N; j++)
        plot[j] = 0; 

    printf("okay1\n");

    m = error(a,b);
    printf("%f\n",m);

    return 0; 
}

float error(int a, int b){
    float product = a*b;
    printf("%f\n",product);
    return product; 
} 

so the m = error(a,b) always gives 0 no matter what!

Please help. I apologise for not cleaning this up...

© Programmers or respective owner

Related posts about c